package com.foreverwin.jzymes.production.debur.controller;

import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.production.debur.service.IDeburNCRecordAdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/production/debur")
public class DeburNCRecordController {
    @Autowired
    IDeburNCRecordAdviceService deburNCRecordAdviceService;

    @RequestMapping("/recordDeburNC")
    public AjaxResult recordDeburNC( @RequestBody Map<String,Object> jsonMap ){
        jsonMap.put( "site", CommonMethods.getSite() );
        try{
            deburNCRecordAdviceService.recordDeburNC( jsonMap );
            return AjaxResult.returnSuccess();
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }

    @RequestMapping("/findDateCodeCnc")
    public AjaxResult findDateCodeCnc( @RequestParam String dateCode ){
        String site = CommonMethods.getSite();
        try{
            String cnc = deburNCRecordAdviceService.findDateCodeCnc( site, dateCode );
            Map<String,String> rtnMap = new HashMap<>();
            rtnMap.put( "cnc", cnc );
            return AjaxResult.returnSuccess().put( "value", rtnMap );
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }
}
